<template>
    <div class="page">

        <div class="weui-header bg-green" style="position: fixed;top: 0; width: 100%;z-index: 500;"> 
            <div class="weui-header-left" @click="goBack">
                <svg class="icon white" aria-hidden="true">
                    <use xlink:href="#icon-fanhui"></use>
                </svg>
            </div>
            <h1 class="weui-header-title">设置测试配置</h1>
        </div>

        <div style="height:50px"></div>

        <div class="weui-cells">
            <div role="option" class="weui-cell ">
                <div class="weui-cell__hd"><span class="weui-label">题目数量</span></div>
                <div class="weui-cell__bd">
                    <input v-model="QUESTION_NUMBER" class="weui-input" placeholder="填写希望测验的题目数量" type="number" pattern="[0-9]*">
                </div>
            </div>
            <div role="option" class="weui-cell ">
                <div class="weui-cell__hd"><span class="weui-label">分钟数</span></div>
                <div class="weui-cell__bd">
                    <input v-model="TEST_TIME"  class="weui-input" placeholder="填写考试时间，单位为分钟" type="number" pattern="[0-9]*">
                </div>
            </div>
        </div>
        
        <div class="page__ft">
           <div class="weui-footer weui-footer_fixed-bottom">
               <a href="javascript:" role="button" class="weui-btn weui-btn_primary" style="color:#fff" @click="toNextPage">开始测试</a>
           </div>
        </div>
    </div>
</template>

<script>
 
export default {
    data () {
        return {
            QUESTION_NUMBER:100,
            TEST_TIME:60,
            checkedList:[]
        }
    },
    methods: {
        goBack(){
            this.$router.go(-1);
        },
        toNextPage(){

            if(this.QUESTION_NUMBER>200){
                this.$weui.alert("题目数不能大于200");
                return
            }

            var loading           = this.$weui.loading('数据处理中…');

            var createTestRequest = this.$store.state.createTestRequest;
            
            this.$api.Training.CreateTest({
                QUESTION_NUMBER : this.QUESTION_NUMBER,
                TEST_TIME       : this.TEST_TIME,
                CLASS_LIST      : createTestRequest.CLASS_LIST
            }).then((msg)=>{

                loading.hide();

                if(msg.data.R){
                    
                    this.$store.commit('setcreateTestRequest',{
                        TEST_TIME       : this.TEST_TIME ,
                        QUESTION_NUMBER : this.QUESTION_NUMBER ,
                        CLASS_LIST      : createTestRequest.CLASS_LIST,
                        QUESTIONS       : msg.data.D.QUESTION_LIST
                    });

                    this.$router.push({name:'TestView',title:'12'});

                }
                else{
                    this.$weui.alert(msg.data.I);                                
                }

            }).catch((response)=> {
                loading.hide();
                // 响应错误回调
                this.$weui.alert("调用http错误，代码:" + response.message);
            });
        
        }
    },
    created  () {        
        document.title="测试配置"  
      
    }
}
</script>

<style>

</style>